#include "function.h"
int wpl=0;
void Preorder(Tree T,int deep)
{
    if(T!=NULL)
    {
        if(T->left==NULL&&T->right==NULL)
        {
            wpl=wpl+T->weight*deep;
        }
        Preorder(T->left,deep+1);
        Preorder(T->right,deep+1);
    }
}
int main()
{
    int deep=0;
    Tree pnew;
    ptag pcur=NULL,phead=NULL,ptail=NULL,listpnew=NULL;
    Tree tree=NULL;
    ElemType n;
    while(scanf("%d",&n))
    {
//      if(n=='\n')
//        {
//        break;
//        }
        pnew=(BiTree*)calloc(1, sizeof(BiTree));
        listpnew=(ptag)calloc(1,sizeof(tag_t));
        pnew->weight=n;
        listpnew->p=pnew;
        if(tree==NULL)
        {
            tree=pnew;
            pcur=listpnew;
            phead=listpnew;
            ptail=listpnew;
        }
        else
        {
            ptail->next=listpnew;
            ptail=listpnew;
            if(NULL==pcur->p->left)
            {
                pcur->p->left=pnew;
            }
            else if(NULL==pcur->p->right)
            {
                pcur->p->right=pnew;
                pcur=pcur->next;
            }
        }
    }
    Preorder(tree,deep);
    printf("wpl is =%d\n",wpl);
    return 0;
}